import Vue from 'vue';
import Router from 'vue-router';
import system from './router/system';
import mobile from './router/mobile';
Vue.use(Router);
const routes = [
    {
        path: '/',
        component: () => import('@/common/Home.vue'),
        meta: { title: '首页' },
        children: [...system],
        redirect: 'cloudDiagnosis'
    },
    {
        path: '/login',
        component: () => import('@/common/Login.vue'),
        meta: { title: '登录' }
    },
    {
        path: '/screen/cloudDiagnosis',
        component: () => import('@/view/screen/cloudDiagnosis.vue'),
        meta: { title: '云影像', isWeb: true }
    },
    {
        path: '/screen/cloudShadow',
        component: () => import('@/view/screen/cloudShadow.vue'),
        meta: { title: '云影像', isWeb: true }
    },
    {
        path: '/mobile/checking',
        component: () => import('@/view/mobile/checking/checking.vue'),
        meta: { title: '检查信息', isWeb: false }
    },
    {
        path: '/mobile/checkingzzj',
        component: () => import('@/view/mobile/checking/checkingzzj.vue'),
        meta: { title: '基础信息', isWeb: false }
    }, 
    {
        path: '/mobile/checkingzzjnocheck',
        component: () => import('@/view/mobile/checking/checkingzzjnocheck.vue'),
        meta: { title: '基础信息', isWeb: false }
    }, 

    {
        path: '/mobile/checkingzzjnocheck_xcx',
        component: () => import('@/view/mobile/checking/checkingzzjnocheck_xcx.vue'),
        meta: { title: '基础信息', isWeb: false }
    }, 


    {
        path: '/mobile/report',
        component: () => import('@/view/mobile/checking/report.vue'),
        meta: { title: '报告详情', isWeb: false }
    },
    {
        path: '/mobile/queryCheck',
        component: () => import('@/view/mobile/checking/queryCheck.vue'),
        meta: { title: '检索检查单', isWeb: false }
    },

    {
        path: '/mobile/queryCheckzzj',
        component: () => import('@/view/mobile/checking/queryCheckzzj.vue'),
        meta: { title: '检查单', isWeb: false }
    },

    {
        path: '/mobile/queryCheckjchlist',
        component: () => import('@/view/mobile/checking/queryCheckjchlist.vue'),
        meta: { title: '检查单', isWeb: false }
    },


    {
        path: '/mobile/ordercheckno',
        component: () => import('@/view/mobile/user/order/Ordercheckno.vue'),
        meta: { title: '检查单', isWeb: false }
    },
 
    {
        path: '/mobile/film',
        component: () => import('@/view/mobile/checking/film.vue'),
        meta: { title: '蓝影电子胶片', isWeb: false }
    },
    {
        path: '/mobile/admin',
        component: () => import('@/view/mobile/admin/MobileHome.vue'),
        children: [...mobile],
        redirect: '/mobile/admin/home',
        meta: { title: '手机端' }
    },
    {
        path: '/mobile/admin/login',
        component: () => import('@/view/mobile/admin/login.vue'),
        meta: { title: '登录' }
    }
];

const router = new Router({ mode: 'hash', routes });


//使用钩子函数对路由进行权限跳转
router.beforeEach((to, from, next) => {
    document.title = `${to.meta.title}`;
    if (to.meta.isWeb) {
        const role = window.sessionStorage.getItem('userName');
        if (!role && to.path !== '/login') {
            next('/login');
        } else {
            next();
        }
    } else if (to.meta.isMobileAdmin) {
        const role = window.sessionStorage.getItem('mobileUserName');
        if (!role && to.path !== '/mobile/admin/login') {
            next('/mobile/admin/login');
        } else {
            next();
        }
    } else {
        next();
    }
});

export default router;
